﻿// See https://aka.ms/new-console-template for more information
namespace StudyDemo.Enumerable;

public class EnumerableDemo
{
    /// <summary>
    /// Queue示例,先进先出
    /// </summary>
    static void QueueExample()
    {
        var set = new Queue<int>();
        set.Enqueue(3);
        set.Enqueue(1);
        set.Enqueue(2);
        set.Enqueue(2);
        set.Dequeue();//弹出第一个元素

        foreach (var item in set)
        {
            Console.WriteLine(item);
        }
    }

    /// <summary>
    /// Stack示例，后进先出
    /// </summary>
    static void DequeueExample()
    {
        var set = new Stack<int>();
        set.Push(3);
        set.Push(1);
        set.Push(2);
        set.Push(2);
        set.Pop();
        foreach (var item in set)
        {
            Console.WriteLine(item);
        }
    }


    /// <summary>
    /// HashSet示例
    /// </summary>
    static void HashSetExample()
    {
        var set = new HashSet<int>();
        set.Add(3);
        set.Add(1);
        set.Add(2);
        set.Add(2);

        foreach (var item in set)
        {
            Console.WriteLine(item);
        }
    }
}


